package com.tupi.project.ui.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tupi.project.R;
import com.tupi.project.base.BaseActivity;
import com.tupi.project.bean.PullToRefreshBean;
import com.tupi.project.ui.adapter.PullToRefreshAdapter;
import com.tupi.project.ui.contract.PullToRefreshContract;
import com.tupi.project.ui.presenter.PullToRefreshPresenter;
import com.tupi.project.view.refresh.RefreshHandler;
import com.tupi.project.view.refresh.RefreshLayout;

import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.PtrFrameLayout;

/**
 * PullToRefreshActivity
 * Created by CPP on 2017/11/27.
 */

public class PullToRefreshActivity extends BaseActivity<PullToRefreshPresenter> implements
        PullToRefreshContract.View
{
    private static final String TAG = PullToRefreshActivity.class.getSimpleName();
    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;
    @BindView(R.id.ptr_frame_layout)
    RefreshLayout mPtrFrameLayout;
    
    private PullToRefreshAdapter mAdapter;
    
    @Override
    protected void initInject()
    {
        getActivityComponent().inject(this);
    }
    
    @Override
    protected int getLayout()
    {
        return R.layout.activity_pull_to_refresh;
    }
    
    @Override
    protected void initEventAndData()
    {
        mAdapter = new PullToRefreshAdapter(R.layout.item_pull_to_refresh);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter.setDefaultAdapter(mRecyclerView, new BaseQuickAdapter.RequestLoadMoreListener()
        {
            @Override
            public void onLoadMoreRequested()
            {
                mPresenter.onLoadMoreRequested();
            }
        });
        
        setDefaultPullToRefresh(mPtrFrameLayout, new RefreshHandler()
        {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame)
            {
                mPresenter.onRefreshBegin();
            }
        });
    
    }
    
    
    @Override
    public void onRefreshFinish(List<PullToRefreshBean> detailModelList)
    {
    
        
    }
    
    @Override
    public PullToRefreshAdapter getAdapter()
    {
        return mAdapter;
    }
}
